API Documentation
Public Member Functions | List of all members
nkMemory::StringView Class Referencefinal

Class holding information about a string, with no ownership over the data. More...

Public Member Functions

 StringView ()
 
 StringView (const char *data)
 
 StringView (const char *data, unsigned long long size)
 
 StringView (const String &other)
 
 ~StringView ()
 
const char * getData () const
 
unsigned long long getSize () const
 
bool empty () const
 
char front () const
 
char back () const
 
StringViewoperator= (const char *data)
 
StringViewoperator= (const String &other)
 
char operator[] (unsigned long long index) const
 
bool operator== (const char *other)
 
bool operator== (const String &other)
 
bool operator== (const StringView &other)
 
 StringView (const std::string &str)
 
 StringView (const std::string_view &str)
 
 operator std::string () const
 
 operator std::string_view () const
 

Detailed Description

Class holding information about a string, with no ownership over the data.

This class will abstract a chain of characters and offer some utility to help manipulating them. The aim of this class is not to replace std::string_view within a codebase, but rather to offer a safe data exchange class from an app to the dlls, and the other way around. This class being fully exported, it doesn't suffer from the caveats a template can have in such situations.

To help in this dialog between app and dlls, the class is thought to be as transparent as possible between const char*, std::string_view and other widespread way of representing strings. Typical usage would just be to use standard structures in your app and benefit from the automatic conversions from one type to another.

Note that a view does not own the memory provided. As such, it is pretty fast as no memory shuffling is necessary. However, care must be taken when using it with temporary memory.

Constructor & Destructor Documentation

◆ StringView() [1/6]

nkMemory::StringView::StringView ( )

Default constructor. Will default to a nullptr data and a size of 0.

◆ StringView() [2/6]

nkMemory::StringView::StringView ( const char *  data)

Const char* constructor. Provided memory location will be pointed by the view. Be sure provided data is null-terminated so that its length can correctly be determined.

Parameters
dataThe pointer to the chain of characters to take over.

◆ StringView() [3/6]

nkMemory::StringView::StringView ( const char *  data,
unsigned long long  size 
)

Guided const char* constructor. Provided memory location will be pointed and based on the size given. Prefer this constructor over the const char* constructor if you know the size required.

Parameters
dataThe pointer to the chain of characters to point to.
sizeThe size of the chain provided, in number of chars.

◆ StringView() [4/6]

nkMemory::StringView::StringView ( const String other)

String constructor. Memory location pointed by the String will be pointed.

Parameters
otherThe string to point to.

◆ ~StringView()

nkMemory::StringView::~StringView ( )

Destructor.

◆ StringView() [5/6]

nkMemory::StringView::StringView ( const std::string &  str)

Standard string constructor. The string provided will be pointed by the view.

Parameters
strThe string to point to.

◆ StringView() [6/6]

nkMemory::StringView::StringView ( const std::string_view &  str)

Standard string view constructor. The view provided will be used to find the memory to point to.

Parameters
strThe view to mimick.

Member Function Documentation

◆ getData()

const char* nkMemory::StringView::getData ( ) const
Returns
A pointer over the memory of the view.

◆ getSize()

unsigned long long nkMemory::StringView::getSize ( ) const
Returns
The size of the view, in number of chars.

◆ empty()

bool nkMemory::StringView::empty ( ) const
Returns
Whether the view is of size 0, aka empty (true) or not (false).

◆ front()

char nkMemory::StringView::front ( ) const
Returns
The first char in the view.

◆ back()

char nkMemory::StringView::back ( ) const
Returns
The last char in the view.

◆ operator=() [1/2]

StringView& nkMemory::StringView::operator= ( const char *  data)

Const char* assignment operator.

Parameters
dataThe pointer over the memory to point to.

◆ operator=() [2/2]

StringView& nkMemory::StringView::operator= ( const String other)

String assignment operator.

Parameters
otherThe string to point to.

◆ operator[]()

char nkMemory::StringView::operator[] ( unsigned long long  index) const

Const access operator.

Parameters
indexThe index of the char to access.

◆ operator==() [1/3]

bool nkMemory::StringView::operator== ( const char *  other)

Const char* equality operator.

Parameters
otherThe const char* to check equality with.

◆ operator==() [2/3]

bool nkMemory::StringView::operator== ( const String other)

String equality operator.

Parameters
otherThe string to check equality with.

◆ operator==() [3/3]

bool nkMemory::StringView::operator== ( const StringView other)

View equality operator.

Parameters
otherThe view to check equality with.

◆ operator std::string()

nkMemory::StringView::operator std::string ( ) const

Conversion operator, to std::string.

◆ operator std::string_view()

nkMemory::StringView::operator std::string_view ( ) const

Conversion operator, to std::string_view.


The documentation for this class was generated from the following file: